package com.itheima.app.controller;

import com.itheima.app.videomanager.VideoManager;
import com.itheima.app.interceptor.UserHolder;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class VideoController {

    @Autowired
    private VideoManager videoManager;

    // 视频分页查询
    @GetMapping("/smallVideos")
    public ResponseEntity findVideoVoByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 获取线程内userId
        Long userId = UserHolder.get().getId();
        // 调用manager
        PageBeanVo pageBeanVo = videoManager.findVideoVoByPage(userId, pageNum, pageSize);
        // 返回
        return ResponseEntity.ok(pageBeanVo);
    }
    //关注用户
    @PostMapping("/smallVideos/{focusUserId}/userFocus")
    public void  guanzhu(@PathVariable Long focusUserId){
        Long userId = UserHolder.get().getId();
        videoManager.guanzhu(userId,focusUserId);
    }
    //取消关注
    @PostMapping("/smallVideos/{focusUserId}/userUnFocus")
    public void removeguanzhu(@PathVariable Long focusUserId){
        Long userId = UserHolder.get().getId();
        videoManager.removeguanzhu(userId,focusUserId);
    }
}